package com.gxwy.shenzhou;


public class MingXiRequest{
	private HeaderRequest header =new HeaderRequest(true);
	private String qsjls;
	private String myjls;
	private String dqjls;
	private String zzjls;
	private String sxfbz;
	private String zhdh;
	private String zdje;
	private String zgje;
	private String qsrq;
	private String zzrq;
	private String zjjgh;
	private String gylsh;

	public static final int QSJLS_FLAG = 1;
	public static final int	MYJLS_FLAG = 1;
	public static final int DQJLS_FLAG = 1;
	public static final int ZZJLS_FLAG = 1;
	public static final int SXFBZ_FLAG = 2;
	public static final int ZHDH_FLAG = 2;
	public static final int ZDJE_FLAG = 2;
	public static final int ZGJE_FLAG = 2;
	public static final int QSRQ_FLAG = 2;
	public static final int ZZRQ_FLAG = 2;
	public static final int ZJJGH_FLAG = 2;
	public static final int GYLSH_FLAG = 2;

	public static final int QSJLS_LEN = 5;
	public static final int	MYJLS_LEN = 5;
	public static final int DQJLS_LEN = 5;
	public static final int ZZJLS_LEN = 5;
	public static final int SXFBZ_LEN = 1;
	public static final int ZHDH_LEN = 32;
	public static final int ZDJE_LEN = 15;
	public static final int ZGJE_LEN = 15;
	public static final int QSRQ_LEN = 8;
	public static final int ZZRQ_LEN = 8;
	public static final int ZJJGH_LEN = 3;
	public static final int GYLSH_LEN = 8;
	
	public static final int TOTAL_LEN = QSJLS_LEN+MYJLS_LEN+DQJLS_LEN+ZZJLS_LEN+SXFBZ_LEN+ZHDH_LEN+ZDJE_LEN
				+ZGJE_LEN+QSRQ_LEN+ZZRQ_LEN+ZJJGH_LEN+GYLSH_LEN;
	private int reallen = 0;

	public HeaderRequest getHeader() {
		return header;
	}
	public void setHeader(HeaderRequest header) {
		this.header = header;
	}
	public String getQsjls() {
		return qsjls;
	}
	public void setQsjls(String qsjls) throws Exception{
		if(qsjls==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(qsjls.getBytes("gbk").length<QSJLS_LEN){
			this.qsjls = Supply.supply(qsjls,QSJLS_FLAG,QSJLS_LEN);
		}else if(qsjls.getBytes("gbk").length>QSJLS_LEN){
			Exception e=new Exception("Too long");
			throw e;
		}else{
			this.qsjls = qsjls;		
		}
	}
	
	public String getMyjls() {
		return myjls;
	}
	public void setMyjls(String myjls) throws Exception{
		if(myjls==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(myjls.getBytes("gbk").length<MYJLS_LEN){
			this.myjls = Supply.supply(myjls,MYJLS_FLAG,MYJLS_LEN);
		}else if(myjls.getBytes("gbk").length>MYJLS_LEN){
			Exception e=new Exception("Too long");
			throw e;
		}else{
			this.myjls = myjls;			
		}
	}
	
	public String getDqjls() {
		return dqjls;
	}
	public void setDqjls(String dqjls) throws Exception{
		if(dqjls==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(dqjls.getBytes("gbk").length<DQJLS_LEN){
			this.dqjls = Supply.supply(dqjls,DQJLS_FLAG,DQJLS_LEN);
		}else if(dqjls.getBytes("gbk").length>DQJLS_LEN){
			Exception e=new Exception("Too long");
			throw e;
		}else{
			this.dqjls = dqjls;			
		}
	}
	
	public String getZzjls() {
		return zzjls;
	}
	public void setZzjls(String zzjls) throws Exception{
		if(zzjls==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(zzjls.getBytes("gbk").length<ZZJLS_LEN){
			this.zzjls = Supply.supply(zzjls,ZZJLS_FLAG,ZZJLS_LEN);
		}else if(zzjls.getBytes("gbk").length>ZZJLS_LEN){
			Exception e=new Exception("Too long");
			throw e;
		}else{
			this.zzjls = zzjls;			
		}
	}
	
	public String getSxfbz() {
		return sxfbz;
	}
	public void setSxfbz(String sxfbz) throws Exception{
		if(sxfbz==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(sxfbz.getBytes("gbk").length<SXFBZ_LEN){
			this.sxfbz = Supply.supply(sxfbz,SXFBZ_FLAG,SXFBZ_LEN);
		}else if(sxfbz.getBytes("gbk").length>SXFBZ_LEN){
			Exception e=new Exception("Too long");
			throw e;
		}else{
			this.sxfbz = sxfbz;			
		}
	}
	
	public String getZhdh() {
		return zhdh;
	}
	public void setZhdh(String zhdh) throws Exception{
		if(zhdh==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(zhdh.getBytes("gbk").length<ZHDH_LEN){
			this.zhdh = Supply.supply(zhdh,ZHDH_FLAG,ZHDH_LEN);
		}else if(zhdh.getBytes("gbk").length>ZHDH_LEN){
			Exception e=new Exception("Too long");
			throw e;
		}else{
			this.zhdh = zhdh;			
		}
	}
	
	public String getZdje() {
		return zdje;
	}
	public void setZdje(String zdje) throws Exception{
		if(zdje==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(zdje.getBytes("gbk").length<ZDJE_LEN){
			this.zdje = Supply.supply(zdje,ZDJE_FLAG,ZDJE_LEN);
		}else if(zdje.getBytes("gbk").length>ZDJE_LEN){
			Exception e=new Exception("Too long");
			throw e;
		}else{
			this.zdje = zdje;			
		}
	}
	
	public String getZgje() {
		return zgje;
	}
	public void setZgje(String zgje) throws Exception{
		if(zgje==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(zgje.getBytes("gbk").length<ZGJE_LEN){
			this.zgje = Supply.supply(zgje,ZGJE_FLAG,ZGJE_LEN);
		}else if(zgje.getBytes("gbk").length>ZGJE_LEN){
			Exception e=new Exception("Too long");
			throw e;
		}else{
			this.zgje = zgje;			
		}
	}
	
	public String getQsrq() {
		return qsrq;
	}
	public void setQsrq(String qsrq) throws Exception{
		if(qsrq==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(qsrq.getBytes("gbk").length<QSRQ_LEN){
			this.qsrq = Supply.supply(qsrq,QSRQ_FLAG,QSRQ_LEN);
		}else if(qsrq.getBytes("gbk").length>QSRQ_LEN){
			Exception e=new Exception("Too long");
			throw e;
		}else{
			this.qsrq = qsrq;			
		}
	}
	
	public String getZzrq() {
		return zzrq;
	}
	public void setZzrq(String zzrq) throws Exception{
		if(zzrq==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(zzrq.getBytes("gbk").length<ZZRQ_LEN){
			this.zzrq = Supply.supply(zzrq,ZZRQ_FLAG,ZZRQ_LEN);
		}else if(zzrq.getBytes("gbk").length>ZZRQ_LEN){
			Exception e=new Exception("Too long");
			throw e;
		}else{
			this.zzrq = zzrq;			
		}
	}
	
	public String getZjjgh() {
		return zjjgh;
	}
	public void setZjjgh(String zjjgh) throws Exception{
		if(zjjgh==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(zjjgh.getBytes("gbk").length<ZJJGH_LEN){
			this.zjjgh = Supply.supply(zjjgh,ZJJGH_FLAG,ZJJGH_LEN);
		}else if(zjjgh.getBytes("gbk").length>ZJJGH_LEN){
			Exception e=new Exception("Too long");
			throw e;
		}else{
			this.zjjgh = zjjgh;			
		}
	}
	
	public String getGylsh() {
		return gylsh;
	}
	public void setGylsh(String gylsh) throws Exception{
		if(gylsh==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(gylsh.getBytes("gbk").length<GYLSH_LEN){
			this.gylsh = Supply.supply(gylsh,GYLSH_FLAG,GYLSH_LEN);
		}else if(gylsh.getBytes("gbk").length>GYLSH_LEN){
			Exception e=new Exception("Too long");
			throw e;
		}else{
			this.gylsh = gylsh;			
		}
	}

	public String build() throws Exception{
		if(this.getHeader()==null){
			throw new Exception("Header is null");
		}
		if(this.getQsjls()==null){
			this.setQsjls("");
		}
		if(this.getMyjls()==null){
			this.setMyjls("");
		}
		if(this.getDqjls()==null){
			this.setDqjls("");
		}
		if(this.getZzjls()==null){
			this.setZzjls("");
		}
		if(this.getSxfbz()==null){
			this.setSxfbz("");
		}
		if(this.getZhdh()==null){
			this.setZhdh("");
		}
		if(this.getZdje()==null){
			this.setZdje("");
		}
		if(this.getZgje()==null){
			this.setZgje("");
		}
		if(this.getQsrq()==null){
			this.setQsrq("");
		}
		if(this.getZzrq()==null){
			this.setZzrq("");
		}
		if(this.getZjjgh()==null){
			this.setZjjgh("");
		}
		if(this.getGylsh()==null){
			this.setGylsh("");
		}
		Integer totallen=header.TOTAL_LEN+TOTAL_LEN-header.LEN_LEN;
	    this.getHeader().setLen(totallen.toString());
		return this.getHeader().build()+this.getQsjls()+this.getMyjls()+this.getDqjls()+this.getZzjls()+this.getSxfbz()+this.getZhdh()+
		       this.getZdje()+this.getZgje()+this.getQsrq()+this.getZzrq()+this.getZjjgh()+this.getGylsh();
	}
	public void parse(String str) throws Exception{
		if(str==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(str.getBytes("gbk").length<TOTAL_LEN+header.TOTAL_LEN){
			Exception e=new Exception("Invalid request");
			throw e;
		}else{
			String headerLen=SplitString.splitString(str,reallen, reallen+header.TOTAL_LEN);
			reallen+=header.TOTAL_LEN;
			header.parse(headerLen);
			this.setQsjls(SplitString.splitString(str,reallen,reallen+QSJLS_LEN));
			reallen += QSJLS_LEN;
			this.setMyjls(SplitString.splitString(str,reallen,reallen+MYJLS_LEN));
			reallen += MYJLS_LEN;
			this.setDqjls(SplitString.splitString(str,reallen,reallen+DQJLS_LEN));
			reallen += DQJLS_LEN;
			this.setZzjls(SplitString.splitString(str,reallen,reallen+ZZJLS_LEN));
			reallen += ZZJLS_LEN;
			this.setSxfbz(SplitString.splitString(str,reallen,reallen+SXFBZ_LEN));
			reallen += SXFBZ_LEN;
			this.setZhdh(SplitString.splitString(str,reallen,reallen+ZHDH_LEN));
			reallen += ZHDH_LEN;
			this.setZdje(SplitString.splitString(str,reallen,reallen+ZDJE_LEN));
			reallen += ZDJE_LEN;
			this.setZgje(SplitString.splitString(str,reallen,reallen+ZGJE_LEN));
			reallen += ZGJE_LEN;
			this.setQsrq(SplitString.splitString(str,reallen,reallen+QSRQ_LEN));
			reallen += QSRQ_LEN;
			this.setZzrq(SplitString.splitString(str,reallen,reallen+ZZRQ_LEN));
			reallen += ZZRQ_LEN;
			this.setZjjgh(SplitString.splitString(str,reallen,reallen+ZJJGH_LEN));
			reallen += ZJJGH_LEN;
			this.setGylsh(SplitString.splitString(str,reallen,reallen+GYLSH_LEN));
			reallen += GYLSH_LEN;
		}
	}
	public static void main(String[] args) throws Exception {
		String str="0000024004688081019999111                                                                      1004081019999111     1000007204           0    1   10    0   1018001011000000030931                                           2014020120141202   00000001";
		MingXiRequest mxr=new MingXiRequest();
		mxr.parse(str);
		System.out.println(mxr);
		String str2=mxr.build();
		System.out.println(str);
		System.out.println(str2);
	}
}
